package miningexplorerproject.vue;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JComboBox;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import miningexplorerproject.controller.ControllerWeka;
import miningexplorerproject.model.Attribut;
import miningexplorerproject.model.Individu;

public class ListenerPrincipal implements ActionListener, ChangeListener, ItemListener {
	
	private String checkingStatusSelected;
	private String creditHistorySelected;
	private String savingStatusSelected;
	private String foreignWorkerSelected;
	private String housingSelected;
	private String otherPaymentPlanSelected;
	private String purposeSelected;
	
	private vuePrincipale vueP;
	
	public ListenerPrincipal(vuePrincipale vue) {
		vueP = vue;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		JComboBox cb = new JComboBox<>();
		
		switch (e.getActionCommand()){
		case "checkingStatus":
				cb = (JComboBox)e.getSource();
			checkingStatusSelected = (String)cb.getSelectedItem();
	        break;
		case "creditHistory":
				cb = (JComboBox)e.getSource();
			creditHistorySelected = (String)cb.getSelectedItem();
	        break;
		case "savingStatus":
			cb = (JComboBox)e.getSource();
			savingStatusSelected = (String)cb.getSelectedItem();
	        break;
		case "housing":
			cb = (JComboBox)e.getSource();
			housingSelected = (String)cb.getSelectedItem();
	        break;
		case "otherPaymentPlan":
			cb = (JComboBox)e.getSource();
			otherPaymentPlanSelected = (String)cb.getSelectedItem();
	        break;
		case "purpose":
			cb = (JComboBox)e.getSource();
			purposeSelected = (String)cb.getSelectedItem();
	        break;
		case "foreignWorker":
			cb = (JComboBox)e.getSource();
			foreignWorkerSelected = (String)cb.getSelectedItem();
	        break;
		case "Validate" :
			Individu individu = new Individu(new Attribut(checkingStatusSelected), new Attribut(creditHistorySelected), new Attribut(savingStatusSelected), new Attribut(housingSelected), new Attribut(otherPaymentPlanSelected), new Attribut(purposeSelected), new Attribut(foreignWorkerSelected));
			ControllerWeka control = new ControllerWeka();
			int pourcent = control.computeWithMethodBayes(individu);
			vueResultat result = new vueResultat(pourcent);
			break;
		}
	}
	
	@Override
	public void stateChanged(ChangeEvent e) {
		
	}

	@Override
	public void itemStateChanged(ItemEvent e) {
		}
}	

